/*
326. Power of Three
Total Accepted: 28943 Total Submissions: 80730 Difficulty: Easy

Given an integer, write a function to determine if it is a power of three.

Follow up:
Could you do it without using any loop / recursion?

Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.

Subscribe to see which companies asked this question
https://leetcode.com/problems/power-of-three/
*/
bool isPowerOfThree(int n)
{
    switch(n) {
    case 1:
    case 3:
    case 9:
    case 27:
    case 81:
    case 243:
    case 729:
    case 2187:
    case 6561:
    case 19683:
    case 59049:
    case 177147:
    case 531441:
    case 1594323:
    case 4782969:
    case 14348907:
    case 43046721:
    case 129140163:
    case 387420489:
    case 1162261467:
        return true;
    default:
        return false;
    }
}

class Solution
{
public:
    bool isPowerOfThree(int n)
    {
        if(n <= 0) return false;
        return (1162261467 % n) == 0;
    }
};

/**
int main(int i, char *argv)
{
    unsigned int x;
    x = 1;
    for(;x < 0x7fffffff; x*=3){
        printf("case %u:\n", x);
    }
    return 0;
}
**/
